package com.yanqu.road.entity.activity.peakstronghold;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

//据点战联盟战斗数据
@FieldTypeAnnotation(tableName = "t_c_activity_peak_stronghold_defend_union", autoSave = true)
public class CrossPeakStrongholdDefendUnionData extends DataObject {
    @FieldTypeAnnotation(select = true, update = true, desc = "活动id", isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(update = true, desc = "商会分组", isIndex = true)
    private int unionGroup;
    @FieldTypeAnnotation(update = true, desc = "淘汰赛第几轮", isIndex = true)
    private int round;
    @FieldTypeAnnotation(update = true, desc = "联盟id", isIndex = true)
    private String unionId = "";
    @FieldTypeAnnotation(desc = "分组id")
    private int group;
    @FieldTypeAnnotation(desc = "淘汰赛排名")
    private int rank;
    @FieldTypeAnnotation(desc = "淘汰赛积分")
    private BigInteger score = BigInteger.ZERO;
    @FieldTypeAnnotation(desc = "防守门客数据")
    private List<PeakStrongholdDefendPatrons> defendPatronsList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "联盟据点等级")
    private int star;
    @FieldTypeAnnotation(desc = "血量加成")
    private int hpAdd;
    @FieldTypeAnnotation(desc = "打了谁,商会id-玩家id-伤害")
    private Map<String, Map<Long, BigInteger>> attackUnionMap = new ConcurrentHashMap<>();
    @FieldTypeAnnotation(desc = "被谁打,商会id-玩家id-伤害")
    private Map<String, Map<Long, BigInteger>> defendUnionMap = new ConcurrentHashMap<>();
    @FieldTypeAnnotation(desc = "血量加成")
    private BigInteger totalDamage = BigInteger.ZERO;
    @FieldTypeAnnotation(desc = "组内排名")
    private int groupRank;
    @FieldTypeAnnotation(desc = "组内排名积分")
    private BigInteger groupScore = BigInteger.ZERO;
    @FieldTypeAnnotation(desc = "银两捐献排名")
    private int silverRank;
    @FieldTypeAnnotation(desc = "捐献总银两")
    private BigInteger silver = BigInteger.ZERO;


    public CrossPeakStrongholdDefendUnionData() {
    }


    public CrossPeakStrongholdDefendUnionData(int activityId, int unionGroup, int round, String unionId, int group) {
        this.activityId = activityId;
        this.unionGroup = unionGroup;
        this.round = round;
        this.unionId = unionId;
        this.group = group;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }

    public int getGroup() {
        return group;
    }

    public void setGroup(int group) {
        this.group = group;
    }

    public List<PeakStrongholdDefendPatrons> getDefendPatronsList() {
        return defendPatronsList;
    }

    public void setDefendPatronsList(List<PeakStrongholdDefendPatrons> defendPatronsList) {
        this.defendPatronsList = defendPatronsList;
    }

    public int getRound() {
        return round;
    }

    public String getUnionId() {
        return unionId;
    }

    public int getHpAdd() {
        return hpAdd;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
        }
    }

    public void setRound(int round) {
        if (this.round != round) {
            this.round = round;
            setUpdateOption();
        }

    }

    public void setUnionId(String unionId) {
        if (null == unionId) {
            return;
        }
        if (!this.unionId.equals(unionId)) {
            this.unionId = unionId;
        }
    }

    public void setHpAdd(int hpAdd) {
        if (this.hpAdd != hpAdd) {
            this.hpAdd = hpAdd;
            setUpdateOption();
        }
    }

    public int getStar() {
        return star;
    }

    public void setStar(int star) {
        if (this.star != star) {
            this.star = star;
            setUpdateOption();
        }

    }

    public BigInteger getCurBlood() {
        BigInteger curBlood = BigInteger.ZERO;
        if (defendPatronsList != null) {
            for (PeakStrongholdDefendPatrons patrons : defendPatronsList) {
                curBlood = curBlood.add(patrons.getCurBlood());
            }
        }
        return curBlood;
    }

    public boolean isBloodEmpty() {
        if (defendPatronsList != null) {
            for (PeakStrongholdDefendPatrons patrons : defendPatronsList) {
                if (patrons.getCurBlood().compareTo(BigInteger.ZERO) == 1) {
                    return false;
                }
            }
        }
        return true;
    }

    public BigInteger getTotalBlood() {
        BigInteger totalBlood = BigInteger.ZERO;
        if (defendPatronsList != null) {
            for (PeakStrongholdDefendPatrons patrons : defendPatronsList) {
                totalBlood = totalBlood.add(patrons.getTotalBlood());
            }
        }
        return totalBlood;
    }

    public PeakStrongholdDefendPatrons getDefendPatrons() {
        for (PeakStrongholdDefendPatrons patrons : defendPatronsList) {
            if (patrons.getCurBlood().compareTo(BigInteger.ZERO) == 1) {
                return patrons;
            }
        }
        return null;
    }

    public PeakStrongholdDefendPatrons getCurDefendPatrons() {
        for (PeakStrongholdDefendPatrons patrons : defendPatronsList) {
            if (patrons.getCurBlood().compareTo(BigInteger.ZERO) > 0) {
                return patrons;
            }
        }
        return null;
    }

    public Map<String, Map<Long, BigInteger>> getAttackUnionMap() {
        return attackUnionMap;
    }

    public void setAttackUnionMap(ConcurrentHashMap<String, ConcurrentHashMap<Long, BigInteger>> attackUnionMap) {
        this.attackUnionMap = new ConcurrentHashMap<>(attackUnionMap);
    }

    public Map<String, Map<Long, BigInteger>> getDefendUnionMap() {
        return defendUnionMap;
    }

    public void setDefendUnionMap(ConcurrentHashMap<String, ConcurrentHashMap<Long, BigInteger>> defendUnionMap) {
        this.defendUnionMap = new ConcurrentHashMap<>(defendUnionMap);
    }

    public void addAttackDamage(String enemyUnionId, long userId, BigInteger totalDamage) {
        Map<Long, BigInteger> userDamageMap = this.attackUnionMap.get(enemyUnionId);
        if (null == userDamageMap) {
            userDamageMap = new ConcurrentHashMap<>();
            this.attackUnionMap.put(enemyUnionId, userDamageMap);
        }
        userDamageMap.put(userId, totalDamage);
        setUpdateOption();
    }

    public BigInteger getAttackDamage(String enemyUnionId, long userId) {
        Map<Long, BigInteger> userDamageMap = this.attackUnionMap.get(enemyUnionId);
        if (null != userDamageMap && userDamageMap.containsKey(userId)) {
            return userDamageMap.get(userId);
        }

        return BigInteger.ZERO;
    }

    public void addDefendDamage(String enemyUnionId, long userId, BigInteger totalDamage) {
        Map<Long, BigInteger> userDamageMap = this.defendUnionMap.get(enemyUnionId);
        if (null == userDamageMap) {
            userDamageMap = new ConcurrentHashMap<>();
            this.defendUnionMap.put(enemyUnionId, userDamageMap);
        }
        userDamageMap.put(userId, totalDamage);
        setUpdateOption();
    }

    public BigInteger getDefendDamage(String enemyUnionId, long userId) {
        Map<Long, BigInteger> userDamageMap = this.defendUnionMap.get(enemyUnionId);
        if (null != userDamageMap && userDamageMap.containsKey(userId)) {
            return userDamageMap.get(userId);
        }

        return BigInteger.ZERO;
    }

    public BigInteger getTotalDamage() {
        return totalDamage;
    }

    public void setTotalDamage(BigInteger totalDamage) {
        this.totalDamage = totalDamage;
    }

    public void addTotalDamage(BigInteger damage) {
        this.totalDamage = this.totalDamage.add(damage);
        setUpdateOption();
    }

    public int getGroupRank() {
        return groupRank;
    }

    public void setGroupRank(int groupRank) {
        if (this.groupRank != groupRank) {
            this.groupRank = groupRank;
            setUpdateOption();
        }
    }

    public BigInteger getGroupScore() {
        return groupScore;
    }

    public void setGroupScore(BigInteger groupScore) {
        if (this.groupScore.compareTo(groupScore) != 0) {
            this.groupScore = groupScore;
            setUpdateOption();
        }
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public BigInteger getScore() {
        return score;
    }

    public void setScore(BigInteger score) {
        this.score = score;
    }

    public int getSilverRank() {
        return silverRank;
    }

    public void setSilverRank(int silverRank) {
        if (this.silverRank != silverRank) {
            this.silverRank = silverRank;
            setUpdateOption();
        }
    }

    public BigInteger getSilver() {
        return silver;
    }

    public void setSilver(BigInteger silver) {
        if (this.silver.compareTo(silver) != 0) {
            this.silver = silver;
            setUpdateOption();
        }
    }

    public int getUnionGroup() {
        return unionGroup;
    }

    public void setUnionGroup(int unionGroup) {
        this.unionGroup = unionGroup;
    }
}
